4. 10 pts total. 4pts - looking for the correct place to insert. 4 pts
- pointer manipulation. 2pts - miscellaneous.
Insert(int age, int weight, PLIST_ENTRY ageList, PLIST_ENTRY weightList)
{
PMYSTRUCT newStruct= new MYSTRUCT;
newStruct->age = age;
newStruct->weight = weight;
//insert in age list
for (PLIST_ENTRY pAge=ageList.FLink; pAge!=ageList;
pAge=pAge.FLink)
{
PMYSTRUCT pMyStruct
= CONTAINING_RECORD(pAge, MYSTRUCT, SortByAge);
if (pMyStruct->age >
age)
break;
}
newStruct->SortByAge->FLink = pAge;
newStruct->SortByAge->BLink = pAge->BLink;
pAge->BLink->FLink = newStruct->SortByAge;
pAge->BLink = newStruct->SortByAge;
//insert in weight list
for (PLIST_ENTRY pWeight=weightList.FLink; pWeight!=weightList;
pWeight=pWeight.FLink)
{
PMYSTRUCT pMyStruct
= CONTAINING_RECORD(pWeight, MYSTRUCT, SortByWeight);
if (pMyStruct->weight>
weight)
break;
}
newStruct->SortByAge->FLink = pWeight;
newStruct->SortByAge->BLink = pWeight->BLink;
pWeight->BLink->FLink = newStruct->SortByWeight;
pWeight->BLink = newStruct->SortByWeight;
}